package team.wuyou.util.annotation.log.service;

import org.springframework.stereotype.Service;
import team.wuyou.bean.Result;
import team.wuyou.util.annotation.log.bean.OperationLog;
import team.wuyou.util.jdbc.CommonJDBCUtil;

import java.sql.SQLException;

@Service
public class OperationLogService {

    private static final String INSERT_OPERATION_LOG_SQL = "INSERT INTO OperationLog " +
            "(operId, operModul, operType, operDesc, operMethod, operRequParam, operRespParam, " +
            "operUserName, operIp, operUri, operCreateTime, operVer) " +
            "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
    public Result insert(OperationLog operlog) throws SQLException {
        // 设置实体类的属性值...
        // 现在你可以使用array[]来访问实体类的属性值了
        // 例如，array[0]表示operId的值，array[1]表示operModul的值，以此类推
        int insert = OperationLogService.insertOperationLog(operlog);
        if (insert>0){
            System.out.println("insert OperationLog success");

        }else {

            System.out.println("insert OperationLog fail");
        }

        return null;
    }



    public static int insertOperationLog(OperationLog operationLog) throws SQLException {
        Object[] params = {
                operationLog.getOperId(),
                operationLog.getOperModul(),
                operationLog.getOperType(),
                operationLog.getOperDesc(),
                operationLog.getOperMethod(),
                operationLog.getOperRequParam(),
                operationLog.getOperRespParam(),
                operationLog.getOperUserName(),
                operationLog.getOperIp(),
                operationLog.getOperUri(),
                operationLog.getOperCreateTime(),
                operationLog.getOperVer()
        };

        return CommonJDBCUtil.executeUpdate(INSERT_OPERATION_LOG_SQL,params);

    }

}
